//
//  ST_GiftRankCellModel.swift
//  btvideo
//
//  Created by Jason on 2021/9/15.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import Foundation
import UIKit
import SwiftyJSON

class ST_GiftRankCellModel : NSObject{

    var accid : String
    var avatar : String
    var faceAuditState : Int
    var guardContent : String
    var guardTime : Int
    var intimacy : Int
    var nickname : String
    var vipExpire : Int

    var intimacyImg:String
//    补充
    var index = 0
    
    var leftImageName:String?
    
    var borderColor:UIColor
    
    var sweetValueAttrStr:NSAttributedString
    
    var crownImage:UIImage?
    
    
    var nobilityUrl:String?
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON,row:Int){
        accid = json["accid"].stringValue
        avatar = json["avatar"].stringValue
        faceAuditState = json["face_audit_state"].intValue
        guardContent = json["guard_content"].stringValue
        guardTime = json["guard_time"].intValue
        intimacy = json["intimacy"].intValue
        nickname = json["nickname"].stringValue
        vipExpire = json["vip_expire"].intValue
        intimacyImg = json["intimacy_img"].stringValue
        nobilityUrl = json["nobility_img"].stringValue
        
        index = row
        
        
        
        let str = NSMutableAttributedString.init(string: intimacy.string)
        
        switch index {
        case 0:
            leftImageName = "sweetRank1"
            
            let tintColor = UIColor.init(hex: 0xFEC207)!
            
            borderColor = tintColor
            
            let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold),.foregroundColor: tintColor]
            
            str.addAttributes(attr, range: NSRange(location: 0, length: str.length))
            
            crownImage = ST_ImageUtils.imageName("密友_冠军_icon")
            
        case 1:
            leftImageName = "sweetRank2"
            
            let tintColor = UIColor.init(hex: 0xBAC1D0)!
            
            borderColor = tintColor
            
            let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold),.foregroundColor: tintColor]
            
            str.addAttributes(attr, range: NSRange(location: 0, length: str.length))
            
            crownImage = ST_ImageUtils.imageName("密友_亚军_icon")
        case 2:
            leftImageName = "sweetRank3"
            
            let tintColor = UIColor.init(hex: 0xF4AA51)!
            
            borderColor = tintColor
            
            let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold),.foregroundColor: tintColor]
            
            str.addAttributes(attr, range: NSRange(location: 0, length: str.length))
            
            crownImage = ST_ImageUtils.imageName("密友_季军_icon")
        default:
            borderColor = .clear
                      
            let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold),.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)]
            
            str.addAttributes(attr, range: NSRange(location: 0, length: str.length))
        }
        
        sweetValueAttrStr = str
        
        super.init()
        
    }
}



extension ST_GiftRankCellModel{
    

    static func create_test_case()->ST_GiftRankCellModel {
        
        let str = "{\"intimacy\":199,\"id\":483471,\"gender\":1,\"nickname\":\"你是理财奋斗精神李逵负荆临时冻结返利高赶进度开了房吉林省的房间里，范德萨发生的哈哈哈\",\"avatar\":\"http://dev-btstatic-cdn.jingniaoapps.com/4C572078-7845-4283-8D7E-0733C0602278\",\"face_audit_state\":3,\"accid\":\"5025c4b4e1e81786e7cf956ae29e4f98\",\"vip_expire\":1642559070,\"guard_content\":\"\",\"guard_time\":0,\"intimacy_img\":\"http://dev-btstatic-cdn.jingniaoapps.com/7xe8841623046783\",\"nobility_img\":\"http://dev-btstatic-cdn.jingniaoapps.com/on7cfqa1630399869\"}"
        
        let json = JSON(parseJSON: str)
        
        return ST_GiftRankCellModel(fromJson: json, row: 2)
        
        
    }
    
}
